package com.hotel.management.controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * 主页控制器
 * 处理根路径访问和系统首页
 * 
 * @author Hotel Management Team
 * @version 1.0.0
 * @since 2024-06-28
 */
@RestController
@RequestMapping("/")
public class HomeController {

    /**
     * 系统首页
     * 
     * @return 系统首页信息
     */
    @GetMapping
    public Map<String, Object> home() {
        Map<String, Object> result = new HashMap<>();
        result.put("title", "酒店管理系统");
        result.put("version", "1.0.0");
        result.put("status", "运行中");
        result.put("message", "欢迎访问酒店管理系统API服务");
        result.put("timestamp", new Date());
        
        // API端点信息
        Map<String, String> endpoints = new HashMap<>();
        endpoints.put("健康检查", "/health");
        endpoints.put("系统信息", "/health/info");
        endpoints.put("欢迎页面", "/health/welcome");
        endpoints.put("API文档", "/doc.html");
        endpoints.put("监控面板", "/actuator");
        endpoints.put("数据库监控", "/druid");
        
        result.put("endpoints", endpoints);
        
        // 系统特性
        result.put("features", new String[]{
            "RESTful API设计",
            "Spring Boot 2.7.18",
            "MySQL 8.0数据库",
            "MyBatis数据访问",
            "Druid连接池",
            "统一异常处理",
            "参数验证",
            "API文档生成",
            "系统监控"
        });
        
        return result;
    }

    /**
     * API概览
     * 
     * @return API概览信息
     */
    @GetMapping("/api")
    public Map<String, Object> apiOverview() {
        Map<String, Object> result = new HashMap<>();
        result.put("name", "酒店管理系统API");
        result.put("version", "v1.0.0");
        result.put("description", "提供完整的酒店管理功能API接口");
        result.put("baseUrl", "/api");
        result.put("timestamp", new Date());
        
        // API模块
        Map<String, String> modules = new HashMap<>();
        modules.put("员工管理", "/employees");
        modules.put("房间管理", "/rooms");
        modules.put("客户管理", "/customers");
        modules.put("预订管理", "/reservations");
        modules.put("入住管理", "/checkins");
        modules.put("财务管理", "/finance");
        modules.put("系统管理", "/system");
        
        result.put("modules", modules);
        
        // 技术栈
        Map<String, String> techStack = new HashMap<>();
        techStack.put("框架", "Spring Boot 2.7.18");
        techStack.put("数据库", "MySQL 8.0");
        techStack.put("ORM", "MyBatis + Spring Data JPA");
        techStack.put("连接池", "Druid");
        techStack.put("文档", "Swagger/Knife4j");
        techStack.put("监控", "Spring Boot Actuator");
        
        result.put("techStack", techStack);
        
        return result;
    }

    /**
     * 系统状态
     * 
     * @return 系统运行状态
     */
    @GetMapping("/status")
    public Map<String, Object> status() {
        Map<String, Object> result = new HashMap<>();
        result.put("status", "RUNNING");
        result.put("uptime", System.currentTimeMillis());
        result.put("timestamp", new Date());
        
        // 运行环境信息
        Map<String, Object> environment = new HashMap<>();
        environment.put("java.version", System.getProperty("java.version"));
        environment.put("java.vendor", System.getProperty("java.vendor"));
        environment.put("os.name", System.getProperty("os.name"));
        environment.put("os.version", System.getProperty("os.version"));
        environment.put("user.timezone", System.getProperty("user.timezone"));
        
        result.put("environment", environment);
        
        // 内存使用情况
        Runtime runtime = Runtime.getRuntime();
        Map<String, String> memory = new HashMap<>();
        memory.put("total", (runtime.totalMemory() / 1024 / 1024) + " MB");
        memory.put("free", (runtime.freeMemory() / 1024 / 1024) + " MB");
        memory.put("used", ((runtime.totalMemory() - runtime.freeMemory()) / 1024 / 1024) + " MB");
        memory.put("max", (runtime.maxMemory() / 1024 / 1024) + " MB");
        
        result.put("memory", memory);
        
        return result;
    }
}
